local skel = fk.CreateSkill {
  name = "emo__bailan",
}

skel:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryRound)
  end,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0 then
      return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data
        return use.from == player and use.tos and table.find(use.tos, function (p)
          return p ~= player
        end) ~= nil
      end, Player.HistoryTurn) == 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, skill_name = skel.name, targets = player.room.alive_players,
      prompt = "#emo__bailan-choose",
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]---@type ServerPlayer
    to:gainAnExtraTurn(true, skel.name, {Player.Start, Player.Draw, Player.Play, Player.Discard, Player.Finish})
  end,
})


Fk:loadTranslationTable{
  ["emo__bailan"] = "摆烂",
  [":emo__bailan"] = "每轮限一次，回合结束时，若你本回合没有对其他角色使用牌，你可以令一名角色获得一个无判定阶段的额外回合。",

  ["#emo__bailan-choose"] = "摆烂：可以令一名角色获得一个无判定阶段的额外回合",
}

return skel
